<template>
  <!-- 新增 修改 详情 -->
  <el-dialog
    width="500px"
    title="云池自动审批"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    :before-close="cancel">
    <el-form ref="formRef" :model="form" :rules="rules" size="small" label-width="150px">
      <!-- 供应商云池自动审批开关 0：手动审批 1：自动审批通过 默认0 -->
      <el-form-item label="审批方式" prop="autoVerify">
        <el-radio-group v-model="form.autoVerify">
          <el-radio :label="0">手动审批</el-radio>
          <el-radio :label="1">自动审批通过</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        @click="handleSubmit"
        v-hasPermi="['distribution:user:updateDistributorAutoVerifyById']">
        确 定
      </el-button>
      <el-button @click="cancel">关 闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { updateDistributorAutoVerifyById } from '@/api/platform/supplierManage'

export default {
  props: {
    /**
     * formData
     */
    formData: {
      type: Object,
      default: () => ({}),
    },
    /**
     * type
     */
    type: {
      type: String,
      default: 'add',
    },
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      required: true,
      default: false,
    },
  },
  data() {
    return {
      form: {
        autoVerify: 0,
      },
      // 表单校验
      rules: {
        autoVerify: [{ required: true, message: '请选择', trigger: 'blur' }],
      },
    }
  },
  computed: {},
  watch: {
    show: function (newValue) {
      if (newValue) {
        this.resetForm()
        this.form.autoVerify = this.formData.autoVerify
      }
    },
  },
  methods: {
    handleSubmit() {
      const data = {
        id: this.formData.id,
        autoVerify: this.form.autoVerify,
      }
      updateDistributorAutoVerifyById(data).then((res) => {
        const { code, msg } = res
        if (code === 200) {
          this.$message({ type: 'success', message: msg})

          this.$emit('getList')
          this.cancel()
        }
      })
    },
    resetForm() {
      Object.keys(this.form).forEach((key) => (this.form[key] = ''))
    },

    cancel() {
      this.$emit('update:show', false)
    },
  },
}
</script>
<style scoped lang="scss"></style>
